<template>
  <div class="hello">
    <div>
      <h2>欢迎光临呱呱的小店</h2>
      <div>请选择你的服务员</div>
    </div>
    <div>
      <button
        v-for="(item, index) in girls"
        :key="index"
        @click="girlsnumFun(index)"
      >
        {{ item }}
      </button>
    </div>
    <div>当前选择的是 【{{ girlsnum }}】</div>
  </div>
</template>

<script lang="ts">
import { reactive, toRefs } from "vue";

interface DataProps{
    girls: string[];
    girlsnum: string;
    girlsnumFun: (item: number) => void;
}

export default {
  name: "dome2",
  setup() {
    // * reactive 控制变量
    const data: DataProps = reactive({
      girls: ["服务员1", "服务员2", "服务员3"],
      girlsnum: '',
      girlsnumFun: (item: number) => {
        data.girlsnum = data.girls[item];
      },
    });
    // ? toRefs
    const refData = toRefs(data)
    return {
        data,
        ...refData
    };
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
